home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / examples / demo2.adb < prev    next >
Text File  |  1994-05-13  |  3KB  |  92 lines

  1. with Instr; use Instr;
  2. with Instr.Child; use Instr.Child;
  3. with Io; use Io;
  4. with Gen_List;
  5. procedure Demo2 is 
  6.  
  7.    type Acc is access Instrument'Class;
  8.     
  9.    package Dash_Board is new Gen_List (Acc);
  10.    use Dash_Board;
  11.    
  12.    procedure Print_Dash_Board (L : List) is
  13.       L1 : List := L;
  14.    begin
  15.  
  16.       while L1 /= Nil loop
  17.          Display_Value (Element (L1).all);
  18.          L1 := Tail (L1);
  19.       end loop;
  20.       New_Line;
  21.       
  22.    end Print_Dash_Board;
  23.  
  24.    DB : List := Nil;
  25.    Inc, Sec : Integer;
  26.    
  27. begin
  28.    DB := Append   (new Speedometer,            -- 1
  29.            Append (new Gauge,                  -- 2
  30.            Append (new Graphic_Gauge,          -- 3
  31.            Append (new Graphic_Gauge,          -- 4
  32.            Append (new Clock,                  -- 5
  33.            Append (new Chronometer,            -- 6
  34.            Append (new Accurate_Clock)))))));  -- 7
  35.  
  36.    Set_Name (Element (DB, 1).all, "Speed");
  37.    Set_Name (Element (DB, 2).all, "Fuel");
  38.    Set_Name (Element (DB, 3).all, "Water");
  39.    Set_Name (Element (DB, 4).all, "Oil");
  40.    Set_Name (Element (DB, 5).all, "Time in NY");
  41.    Set_Name (Element (DB, 6).all, "Chrono");
  42.    Set_Name (Element (DB, 7).all, "Time in Paris");
  43.  
  44.    Speedometer   (Element (DB, 1).all).Value := 45; --  mph
  45.    Gauge         (Element (DB, 2).all).Value := 60; --  %   
  46.    Graphic_Gauge (Element (DB, 3).all).Value := 80; -- %
  47.    Graphic_Gauge (Element (DB, 4).all).Value := 40; --  %   
  48.  
  49.    Init (Clock          (Element (DB, 5).all), 12, 15,  0);
  50.    Init (Chronometer    (Element (DB, 6).all),  0,  0,  0);
  51.    Init (Accurate_Clock (Element (DB, 7).all),  6, 15,  0);
  52.    
  53.    loop
  54.       Print_Dash_board (DB);
  55.       
  56.       if Graphic_Gauge (Element (DB, 3).all).Value < 60 then 
  57.          Put_Line ("There is a leak in the radiator."); 
  58.       end if;
  59.       if Speedometer (Element (DB, 1).all).Value> 50 then 
  60.          Put_Line (" Speed limit is 50 ... "); 
  61.       end if;
  62.       
  63.       if Clock (Element (DB, 5).all).Seconds 
  64.            /= Accurate_Clock (Element (DB, 7).all).Seconds 
  65.       then
  66.          Put_Line (" Your first clock is not very accurate ");       
  67.       end if;
  68.       
  69.       Put ("Give a time increment in milliseconds (0 to terminate) :");
  70.       Get (Inc);
  71.       exit when Inc <= 0;
  72.       Sec := Inc / 1000;
  73.       Increment (Clock          (Element (DB, 5).all), Sec);
  74.       Increment (Chronometer    (Element (DB, 6).all), Sec);
  75.       Increment (Accurate_Clock (Element (DB, 7).all), Inc);
  76.  
  77.       Gauge (Element (DB, 2).all).Value := 
  78.         Integer (Float (Gauge (Element (DB, 2).all).Value) 
  79.                   * (1.0 - Float (Sec) / 3600.0));
  80.  
  81.       Graphic_Gauge (Element (DB, 3).all).Value := 
  82.         Integer (Float (Graphic_Gauge (Element (DB, 3).all).Value)
  83.                    * (1.0 - Float (Sec) / 600.0));
  84.  
  85.       Speedometer (Element (DB, 1).all).Value := 
  86.         Speedometer (Element (DB, 1).all).Value + 2;
  87.    end loop;
  88. exception 
  89.    when Others => Put_Line ("I think that's enough for today... Bye");
  90. end Demo2;
  91.  
  92.